package com.hongyuan.sellfitness.ui.main.view_mode;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableArrayList;
import androidx.databinding.ObservableField;
import androidx.databinding.ObservableList;

import com.hongyuan.mvvmhabitx.binding.command.BindingCommand;
import com.hongyuan.sellfitness.BR;
import com.hongyuan.sellfitness.R;
import com.hongyuan.sellfitness.base.CustomViewModel;
import com.hongyuan.sellfitness.data.MyRepository;
import com.hongyuan.sellfitness.data.md5.BaseUtil;
import com.hongyuan.sellfitness.ui.main.activity.MainActivity;
import com.hongyuan.sellfitness.ui.main.beans.V3SuccessBeans;

import me.tatarka.bindingcollectionadapter2.ItemBinding;

public class SuccessViewModel extends CustomViewModel<MyRepository> {

    public ObservableField<V3SuccessBeans> entity = new ObservableField<>();

    public SuccessViewModel(@NonNull Application application, MyRepository model) {
        super(application, model);
    }

    //给RecyclerView添加ObservableList
    public ObservableList<SuccessItemViewModel> observableList = new ObservableArrayList<>();

    //给RecyclerView添加ItemBinding
    public ItemBinding<SuccessItemViewModel> itemBinding = ItemBinding.of(BR.viewModel, R.layout.item_success);

    //选择位置
    public BindingCommand goMain = new BindingCommand(() -> {
        startActivity(MainActivity.class);
    });

    /*
    * 初始化显示数据
    * */
    public void setEntity(V3SuccessBeans beans){
        if(BaseUtil.isValue(beans)){
            entity.set(beans);
        }

        if(beans.getItemContens() != null && beans.getItemContens().size() > 0){
            for(V3SuccessBeans.ItemConten itemConten:beans.getItemContens()){
                SuccessItemViewModel itemViewModel = new SuccessItemViewModel(this,itemConten);
                observableList.add(itemViewModel);
            }
        }
    }
}
